<?php
require_once(dirname(__FILE__).'/db_mysql.inc');

Class SqlClass
{
	private $conn;

	function connect()
	{
		global $server;
		global $user;
		global $password;
		global $dbName;

		//require_once('db_mysql.inc');
		//connect db
		$this->conn = mysql_connect($server, $user, $password);
		if(!$this->conn)
		{
			echo "Connect db fail! Exit!<br/>".mysql_error();
			exit();
		}

		//select db
		if( !mysql_select_db($dbName) )
		{
			echo "Select db fail! Exit!<br/>".mysql_error();
			mysql_close($this->conn);
			exit();
		}

        //set charactor set
		$sql = "set names 'utf8'";
		if( !mysql_query($sql) )
		{
			echo "Set char set fail! Exit!<br/>".mysql_error();
			mysql_close($this->conn);
			exit();
		}
	}
   

  	function close()
  	{
  		if( !mysql_close($this->conn) )
		{
			echo "Close db fail! Exit<br />".mysql_error();
			exit();
		}
  	}


	function exec_sql($sql)
	{
		$result = mysql_query($sql);
		if( !$result )
		{
			echo "Execute sql fail! Exit!<br/>".mysql_error();
			mysql_close($this->conn);
			exit();
		}
		return $result;
	}

}
?>
